import random

import requests
from util.ip import get_proxies,get_proxies_poll


proxies_poll = get_proxies_poll(1)

urls = [f"https://httpbin.org/get?age={i}" for i in range(100)]

while len(urls):
    try:
        url = urls.pop()
        proxy = random.choice(proxies_poll)
        try:
           res = requests.get(url, proxies=proxy)
           print(res.json())
        except requests.exceptions.ProxyError as e:
            proxies_poll.remove(proxy)
            proxies_poll.append(get_proxies)
            print(f"请求地址{url}失败 错误原因{e}")
        except Exception as e:
            print(f"请求地址{url}失败 错误原因{e}")
            urls.append(url)
    except StopIteration as e:
        print(f"爬虫结束..............")